/*
 * Delay_uS.c
 *
 *  Created on: Dec 13, 2024
 *      Author: admire
 */

#include "Delay_uS.h"

/*
 * 功  能：us延时
 * 参  数：nus(微秒)
 */
void Delay_uS(uint32_t nus)
{
    uint32_t ticks;
    uint32_t told,tnow,tcnt=0;
    uint32_t reload=SysTick->LOAD;
    ticks=nus * 72;
    told=SysTick->VAL;
    while(1)
    {
        tnow=SysTick->VAL;
        if(tnow!=told)
        {
            if(tnow<told)tcnt+=told-tnow;
            else tcnt+=reload-tnow+told;
            told=tnow;
            if(tcnt>=ticks)break;
        }
    };
}


